package guij.taobao;

import java.util.List;

import com.taobao.api.TaobaoApiException;
import com.taobao.api.taobaoke.TaobaokeBaseRestClient;
import com.taobao.api.taobaoke.TaobaokeRestClient;
import com.taobao.api.taobaoke.model.TaobaokeItemDetail;
import com.taobao.api.taobaoke.model.TaobaokeItemsDetailGetRequest;
import com.taobao.api.taobaoke.model.TaobaokeItemsDetailGetResponse;

 
public class TaobaokeInterface {
	private String APP_KEY; 
	private String APP_SERCET;
	private String SANDBOX_URL;
	private String Topke_Nick;
	
	public String getAPP_KEY() {
		return APP_KEY;
	}
	public void setAPP_KEY(String aPPKEY) {
		APP_KEY = aPPKEY;
	}
	public String getAPP_SERCET() {
		return APP_SERCET;
	}
	public void setAPP_SERCET(String aPPSERCET) {
		APP_SERCET = aPPSERCET;
	}
	public String getSANDBOX_URL() {
		return SANDBOX_URL;
	}
	public void setSANDBOX_URL(String sANDBOXURL) {
		SANDBOX_URL = sANDBOXURL;
	}
	public String getTopke_Nick() {
		return Topke_Nick;
	}
	public void setTopke_Nick(String topkeNick) {
		Topke_Nick = topkeNick;
	}
	public TaobaokeRestClient getTaobaokeRestClient() {
		return taobaokeRestClient;
	}
	public void setTaobaokeRestClient(TaobaokeRestClient taobaokeRestClient) {
		this.taobaokeRestClient = taobaokeRestClient;
	}

	TaobaokeRestClient 	taobaokeRestClient;
	public TaobaokeBaseRestClient getTopkeJsonAppClient() throws TaobaoApiException{
		return new TaobaokeBaseRestClient(SANDBOX_URL, APP_KEY, APP_SERCET);
	}
	public String getNick(){
		return Topke_Nick;
	}
	
	public List<TaobaokeItemDetail> GetTaobaokeItem(String numIDs){
		TaobaokeItemsDetailGetRequest req = new TaobaokeItemsDetailGetRequest();
		req.setFields("num_iid,"+
				"title,"+ 
				"nick,"+ 	
				"pic_url,"+ 	
				"price,"+
				"click_url,"+ 
				"commission,"+ 	
				"commission_rate,"+ 	
				"commission_num,"+ 	 
				"commission_volume,"+ 	
				"shop_click_url,"+ 	 	
				"seller_credit_score,"+ 
				"item_location,"+ 	 	
				"keyword_click_url");
		req.setNick(getNick());
		req.setNumIids(numIDs);
		try {
			TaobaokeBaseRestClient client = getTopkeJsonAppClient();
			TaobaokeItemsDetailGetResponse res = client.taobaokeItemsDetailGet(req);
			System.out.println(res.getBody());
			List<TaobaokeItemDetail> itemlist = res.getTaobaokeItemDetails();
			return itemlist;
		} catch (TaobaoApiException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	public String GetTaobaokeItemURL(String numIDs){
		List<TaobaokeItemDetail> items =  GetTaobaokeItem(numIDs);
		if(items!=null&&items.size()>0){
			return items.get(0).getClickUrl();
		}else{
			return null;
		}
	}
	public List<TaobaokeItemDetail> GetTaobaokeItems(String numIDs){
		List<TaobaokeItemDetail> items =  GetTaobaokeItem(numIDs);
		return items;
	}
}
